Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@leafygreen-ui/hooks

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/hooks

LeafyGreen UI Kit Custom Hooks

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
72K
increased by9.78%
Maintainers
3
Weekly downloads
 
Created
Source

Hooks

npm (scoped)

Installation

Yarn

yarn add @leafygreen-ui/hooks

NPM

npm install @leafygreen-ui/hooks

useElementNode

Hook to subscribe to changes in a ref

Example

const Example = () => {
  [refNode, setRefNode] = useElementNode();

  return <div ref={setRefNode}>I am a ref</div>;
};

useEventListener

Hook to create and remove eventListeners

Example

useEventListener('click', handleClick, { enabled });

Properties

PropTypeDescriptionDefault
typeGlobal Event Handler or stringType of event to listen for.
eventCallbackfunctionCallback executed when event is triggered.
optional.optionsAddEventListenerOptionsParameter to specify options passed to the eventListener
optional.enabledbooleanDetermines whether the event handler is attached or not.true
optional.dependenciesArrayArray to be passed to useEffect hook, such that the hook will only run if the array's values have changed.[enabled, type]
optional.elementDocument or HTMLElementThe DOM node to attach the event handler to. Defaults to document.document

useEscapeKey

Hook that listens for EscapeKey press.

Example

useEscapeKey(handleEscapeCallback);

Properties

PropTypeDescriptionDefault
callbackfunctionCallback executed when EscapeKey is pressed.
optionalobjectOptional argument passed to function with implementation specifications. See supported parameters for useEventHandler.

useMutationObserver

Example

const lastTimeContentElMutated = useMutationObserver(
  target,
  mutationOptions,
  () => Date.now(),
  adjustOnMutation,
);

Properties

PropTypeDescriptionDefault
targetHTMLElement or nullHTMLElement to subscribe to changes to.
optionsMutationObserverInitObject with information about what DOM changes to subscribe to. Docs here
callbackfunctionCallback function to execute inside of MutationObserver instance.
enabledbooleanDetermines whether the event handler is attached or not.true

useViewportSize

Hook to subscribe to changes in viewport size

Example

const viewportSize = useViewportSize();

usePoller

Hook to create a Poller that polls at a given interval.

If your onPoll handler returns a Promise it will wait for the Promise to resolve or reject before scheduling the next interval.

This hooks also makes use of the Page Visibility API. If the page is hidden then polling will stop. When a page becomes visible again then polling will resume.

Example

usePoller(onPoll, {
  interval: 30000,
  immediate: true,
  enabled: true,
});

Properties

PropTypeDescriptionDefault
onPollfunctionCallback executed when poll interval occurs.
optional.intervalnumberWhat interval the onPoll should be called.30000
optional.immediatebooleanIf we immediately poll, if false we wait till first interval occurs.true
optional.enabledbooleanIs polling enabled.true

FAQs

Package last updated on 26 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc